package cn.wlinker.video.monitor.controller;

import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.servlet.NoHandlerFoundException;

import java.util.HashMap;
import java.util.Map;

/**
 * 全局异常处理
 *
 * @author gxsjx
 * @version 1.0
 * @date 2025/5/3
 */
@ControllerAdvice
public class GlobalExceptionHandler {

    @ExceptionHandler(NoHandlerFoundException.class)
    public ResponseEntity<Map<String, Object>> handleNoHandlerFoundException(NoHandlerFoundException ex) {
        // 创建自定义的JSON响应
        Map<String, Object> body = new HashMap<>(2);
        body.put("status", HttpStatus.NOT_FOUND.value());
        body.put("message", "Resource not found2");

        // 返回自定义的JSON响应
        return new ResponseEntity<>(body, HttpStatus.NOT_FOUND);
    }
}